package com.oop;
import java.util.Scanner;
public class GuessActivity {
    /**
     * 初始化电视数据
     */
    public Tv init(){
        //电视对象数组
        Tv[] tvs = new Tv[3];
        tvs[0] = new Tv("Redmi 红米电视","L55R6-A",2199);
        tvs[1] = new Tv("TCL 55V2-PR0","55V2-PR0",2999);
        tvs[2] = new Tv("海信75E3F","75E3F",4799);
        int index = (int)(Math.random()*3);
        Tv randomTv = tvs[index];
        return randomTv;
    }
    public void guess(){
        Scanner input = new Scanner(System.in);
        int guessPrice = 0;
        Tv randomTv = init();
        System.out.println("请猜测【" + randomTv.brand + "】液晶电视商品的价格:");
        int count = 0;
        do {
            System.out.print("请输入竞猜电视商品的价格:");
            guessPrice = input.nextInt();
            if (guessPrice > randomTv.price){
                System.out.println("再小一些，再才一次吧!");
                count++;
            }
            else {
                System.out.println("恭喜你，猜对了，你猜中的电视商品信息如下：");
                randomTv.show();
                break;
            }
            if (count > 2){
                System.out.println("抱歉，你猜错了3次，感谢你的参与，期待下次中奖。");
                break;
            }
        }while (true);

    }

    public static void main(String[] args) {
        GuessActivity gm = new GuessActivity();
        gm.init();
        gm.guess();
    }
}
